package com.heima.article.controller.v1;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.heima.article.service.ApArticleService;
import com.heima.article.service.AuthorServce;
import com.heima.model.article.pojos.ApArticle;
import com.heima.model.article.pojos.ApAuthor;
import com.heima.model.common.dtos.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(value = "作者用户API",tags = "作者用户API")
@RestController
@RequestMapping("/api/v1/author")
public class AuthorController {
    @Autowired
    AuthorServce authorServce;
    @Autowired
    ApArticleService articleService;

    @ApiOperation("根据id查询作者")
    @GetMapping("/findByUserId/{id}")
    public ResponseResult findByUserId(@PathVariable("id") Integer id){
        return ResponseResult.okResult(
                authorServce.getOne(Wrappers.<ApAuthor>lambdaQuery()
                .eq(ApAuthor::getUserId,id)));
    }
    @ApiOperation("根据id添加作者")
    @PostMapping("/save")
    public ResponseResult save(@RequestBody ApAuthor author){
        return ResponseResult.okResult(authorServce.save(author));
    }


    @ApiOperation(value = "查询文章")
    @GetMapping("/get/{id}")
    public ResponseResult<ApArticle> get(@PathVariable("id")Long id){
        return ResponseResult.okResult(articleService.getById(id));
    }
}
